package com.ruoyi.monitor.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.ruoyi.monitor.Vo.MsgCountVo;
import com.ruoyi.monitor.domain.SysMsg;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 邮箱发送Mapper接口
 * 
 * @author 徐泽炫
 * @date 2023-02-22
 */
public interface SysMsgMapper extends BaseMapper<SysMsg>
{

    @Select(" SELECT COUNT(a.rank) as alarmCount\n" +
            " from\n" +
            " (\n" +
            "SELECT  rank\n" +
            "from sys_msg\n" +
            "${ew.customSqlSegment}"+
            "GROUP BY rank\n" +
            " )as a")
    List<MsgCountVo> countsOfAlarm(@Param(Constants.WRAPPER) QueryWrapper<SysMsg> wrapper);
//            "WHERE rank LIKE '%hanghai%'\n" +
    @Select(" SELECT a.`date`,COUNT(IF(type = '邮件',true,null)) as 'mailCount',COUNT(IF(type = '短信',true,null)) as 'messCount'\n" +
            "FROM\n" +
            "(\n" +
            "SELECT DATE_FORMAT(date,'%Y-%m-%d') as 'date',COUNT(id) as id,type\n" +
            "FROM sys_msg\n" +
            "GROUP BY date,type\n" +
            ") \n" +
            "as a\n" +
            "${ew.customSqlSegment}"+
            "GROUP BY a.`date`")
    List<MsgCountVo> countsOfDays(@Param(Constants.WRAPPER) QueryWrapper<SysMsg> wrapper);
    /**
     * 查询邮箱发送
     * 
     * @param id 邮箱发送主键
     * @return 邮箱发送
     */
    public SysMsg selectSysMsgById(Integer id);

    /**
     * 查询邮箱发送列表
     * 
     * @param sysMsg 邮箱发送
     * @return 邮箱发送集合
     */
    public List<SysMsg> selectSysMsgList(SysMsg sysMsg);

    /**
     * 新增邮箱发送
     * 
     * @param sysMsg 邮箱发送
     * @return 结果
     */
    public int insertSysMsg(SysMsg sysMsg);

    /**
     * 修改邮箱发送
     * 
     * @param sysMsg 邮箱发送
     * @return 结果
     */
    public int updateSysMsg(SysMsg sysMsg);

    /**
     * 删除邮箱发送
     * 
     * @param id 邮箱发送主键
     * @return 结果
     */
    public int deleteSysMsgById(Integer id);

    /**
     * 批量删除邮箱发送
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteSysMsgByIds(Integer[] ids);
}
